# i18n.py
"""
Internationalization support.
"""
import html5lib
import xml.etree.ElementTree as ETM
import vocabulary

def html_translated(path, language):
    """
    Load Lib-Ray Menu HTML page from path and return translation into language.
    """
    with open(path, 'rb') as f:
        page = html5lib.parse(f)
    for element in page.iter():
        label = element.get('label', None)
        if label:
            try:
                xlated = vocabulary.buttons[label][language]
            except KeyError:
                xlated = None
            if xlated:
                element.text = xlated
    return ETM.tostring(page)

